package com.cyz.web.app.function.lambda;

import lombok.extern.slf4j.Slf4j;

import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;

/**
 * 测试
 */
@Slf4j
public class Demo1 {

    public static void main(String[] args) {

        new Thread(()->{
           log.info("{} 线程正在执行", Thread.currentThread().getId());
        }).start();


        int res = calcInt(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left + right;
            }
        });

        //简化操作
        res = calcInt((a,b)->{
            return a + b;
        });

        System.out.println(res);

        //调用服务提供者方法
        printNum(new IntPredicate() {
            @Override
            public boolean test(int value) {
                return value%2==0;
            }
        });

        //简化

        printNum((num) ->{
            return num%2==0;
        });


    }

    public static boolean compInt(int num){
        return num%2==0;
    }


    public static int calcInt(IntBinaryOperator operator){
        int a = 10;
        int b = 20;

        return operator.applyAsInt(a, 10);
    }

    public static void printNum(IntPredicate predicate){
        int[] nums = {1,2,3,4,5,6,7,8,9,10};

        for (int num : nums){
            if (predicate.test(num)){
                System.out.println(num);
            }
        }


    }


}
